package com.example.appxi;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.widget.ImageView;
import android.widget.Toast;

public class TransitionActivity extends Activity{
	
	
	Handler h;
    private AnimationDrawable frameAnimation;
    private ImageView view;
    Intent intent;
    String[] temprows;
	
	
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_transition);
		
		intent=getIntent();
		Bundle R_data = intent.getExtras();
		temprows = R_data.getStringArray("place_info");
		
   		Toast toast = Toast.makeText(this, temprows[0], Toast.LENGTH_LONG);	
   		toast.show();


        view = (ImageView) findViewById(R.id.transition_ani);
  

        view.setBackgroundResource(R.drawable.transition_animation);
  
        
        frameAnimation = (AnimationDrawable) view.getBackground();
		
		
		
		h = new Handler();
		h.postDelayed(irun, 2000);
		
		
		
		
	}
	
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {

            frameAnimation.start();
        } else {

            frameAnimation.stop();
        }
    }
	
	
	
	Runnable irun = new Runnable() {
		public void run(){
			Intent i = new Intent(TransitionActivity.this,PlaceActivity.class);
    		Bundle R_data = new Bundle();
    		R_data.putStringArray("place_info", temprows);
    		i.putExtras(R_data);
			startActivity(i);
			finish();
			
			overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
		}
		};
	
	public void onBackPressed() {
		super.onBackPressed();
		h.removeCallbacks(irun);
	}
}